package com.cmdandroid.icebutton;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.provider.ContactsContract;
import android.provider.ContactsContract.CommonDataKinds.Phone;

class NewContactsAdapterBridge extends ContactsAdapterBridge {
	

	
	
//	String name, number, id;
	ArrayList<String> info = new ArrayList<String>();
	List<String> getInfo (Activity a, Intent data) {
		
		
		
		Cursor cursor = null;
		String phoneNumber = "";
		String name = "";
		//Info is stored as {Name, number0}
		List<String> info = new ArrayList<String>();
		int phoneIdx = 0;
		
		Uri contactData = data.getData();

		Cursor cursorName = a.managedQuery(contactData, null, null, null, null);

		if (cursorName.moveToFirst()) {		
			name = cursorName.getString(cursorName.getColumnIndexOrThrow
					(ContactsContract.Contacts.DISPLAY_NAME));
			//clear info first
			info.clear();
			info.add(name);
			
		}
		//TODO: Implement phone Type
		try {
			Uri result = data.getData();
			String id = result.getLastPathSegment();
			//Create cursor to look for phone numbers that belong to
			//selected contacts ID
			cursor = a.getContentResolver().query(Phone.CONTENT_URI,
					null,
					Phone.CONTACT_ID + "=?",
					new String[] { id },
					null);
			phoneIdx = cursor.getColumnIndex(Phone.DATA);
			if (cursor.moveToFirst()) {
				while (cursor.isAfterLast() == false) {
					phoneNumber = cursor.getString(phoneIdx);
					info.add(phoneNumber);
					cursor.moveToNext();
				}
			}
			else {
				//no results actions
			}
			
		} catch (Exception e) {
			//error actions
		} finally {
			if (cursor != null) {
				cursor.close();
			}
			
		}
		return info;
	}
		
}
